// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement
{
	public sealed class AnalyzeRequestParameters : RequestParameters<AnalyzeRequestParameters>
	{
	}

	public sealed partial class AnalyzeRequest : PlainRequestBase<AnalyzeRequestParameters>
	{
		public AnalyzeRequest()
		{
		}

		public AnalyzeRequest(Elastic.Clients.Elasticsearch.IndexName? index) : base(r => r.Optional("index", index))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IndexManagementAnalyze;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonInclude]
		[JsonPropertyName("analyzer")]
		public string? Analyzer { get; set; }

		[JsonInclude]
		[JsonPropertyName("attributes")]
		public IEnumerable<string>? Attributes { get; set; }

		[JsonInclude]
		[JsonPropertyName("char_filter")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Analysis.CharFilter>? CharFilter { get; set; }

		[JsonInclude]
		[JsonPropertyName("explain")]
		public bool? Explain { get; set; }

		[JsonInclude]
		[JsonPropertyName("field")]
		public Elastic.Clients.Elasticsearch.Field? Field { get; set; }

		[JsonInclude]
		[JsonPropertyName("filter")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? Filter { get; set; }

		[JsonInclude]
		[JsonPropertyName("normalizer")]
		public string? Normalizer { get; set; }

		[JsonInclude]
		[JsonPropertyName("text")]
		[JsonConverter(typeof(TextToAnalyzeConverter))]
		public IEnumerable<string>? Text { get; set; }

		[JsonInclude]
		[JsonPropertyName("tokenizer")]
		public Elastic.Clients.Elasticsearch.Analysis.Tokenizer? Tokenizer { get; set; }
	}

	public sealed partial class AnalyzeRequestDescriptor<TDocument> : RequestDescriptorBase<AnalyzeRequestDescriptor<TDocument>, AnalyzeRequestParameters>
	{
		internal AnalyzeRequestDescriptor(Action<AnalyzeRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public AnalyzeRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IndexManagementAnalyze;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public AnalyzeRequestDescriptor<TDocument> Index(Elastic.Clients.Elasticsearch.IndexName? index)
		{
			RouteValues.Optional("index", index);
			return Self;
		}

		private string? AnalyzerValue { get; set; }

		private IEnumerable<string>? AttributesValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Analysis.CharFilter>? CharFilterValue { get; set; }

		private bool? ExplainValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? FilterValue { get; set; }

		private string? NormalizerValue { get; set; }

		private IEnumerable<string>? TextValue { get; set; }

		private Elastic.Clients.Elasticsearch.Analysis.Tokenizer? TokenizerValue { get; set; }

		public AnalyzeRequestDescriptor<TDocument> Analyzer(string? analyzer)
		{
			AnalyzerValue = analyzer;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Attributes(IEnumerable<string>? attributes)
		{
			AttributesValue = attributes;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> CharFilter(IEnumerable<Elastic.Clients.Elasticsearch.Analysis.CharFilter>? charFilter)
		{
			CharFilterValue = charFilter;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Explain(bool? explain = true)
		{
			ExplainValue = explain;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field? field)
		{
			FieldValue = field;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
		{
			FieldValue = field;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Filter(IEnumerable<Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? filter)
		{
			FilterValue = filter;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Normalizer(string? normalizer)
		{
			NormalizerValue = normalizer;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Text(IEnumerable<string>? text)
		{
			TextValue = text;
			return Self;
		}

		public AnalyzeRequestDescriptor<TDocument> Tokenizer(Elastic.Clients.Elasticsearch.Analysis.Tokenizer? tokenizer)
		{
			TokenizerValue = tokenizer;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(AnalyzerValue))
			{
				writer.WritePropertyName("analyzer");
				writer.WriteStringValue(AnalyzerValue);
			}

			if (AttributesValue is not null)
			{
				writer.WritePropertyName("attributes");
				JsonSerializer.Serialize(writer, AttributesValue, options);
			}

			if (CharFilterValue is not null)
			{
				writer.WritePropertyName("char_filter");
				JsonSerializer.Serialize(writer, CharFilterValue, options);
			}

			if (ExplainValue.HasValue)
			{
				writer.WritePropertyName("explain");
				writer.WriteBooleanValue(ExplainValue.Value);
			}

			if (FieldValue is not null)
			{
				writer.WritePropertyName("field");
				JsonSerializer.Serialize(writer, FieldValue, options);
			}

			if (FilterValue is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterValue, options);
			}

			if (!string.IsNullOrEmpty(NormalizerValue))
			{
				writer.WritePropertyName("normalizer");
				writer.WriteStringValue(NormalizerValue);
			}

			if (TextValue is not null)
			{
				writer.WritePropertyName("text");
				SingleOrManySerializationHelper.Serialize<string>(TextValue, writer, options);
			}

			if (TokenizerValue is not null)
			{
				writer.WritePropertyName("tokenizer");
				JsonSerializer.Serialize(writer, TokenizerValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class AnalyzeRequestDescriptor : RequestDescriptorBase<AnalyzeRequestDescriptor, AnalyzeRequestParameters>
	{
		internal AnalyzeRequestDescriptor(Action<AnalyzeRequestDescriptor> configure) => configure.Invoke(this);
		public AnalyzeRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IndexManagementAnalyze;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public AnalyzeRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index)
		{
			RouteValues.Optional("index", index);
			return Self;
		}

		private string? AnalyzerValue { get; set; }

		private IEnumerable<string>? AttributesValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Analysis.CharFilter>? CharFilterValue { get; set; }

		private bool? ExplainValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field? FieldValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? FilterValue { get; set; }

		private string? NormalizerValue { get; set; }

		private IEnumerable<string>? TextValue { get; set; }

		private Elastic.Clients.Elasticsearch.Analysis.Tokenizer? TokenizerValue { get; set; }

		public AnalyzeRequestDescriptor Analyzer(string? analyzer)
		{
			AnalyzerValue = analyzer;
			return Self;
		}

		public AnalyzeRequestDescriptor Attributes(IEnumerable<string>? attributes)
		{
			AttributesValue = attributes;
			return Self;
		}

		public AnalyzeRequestDescriptor CharFilter(IEnumerable<Elastic.Clients.Elasticsearch.Analysis.CharFilter>? charFilter)
		{
			CharFilterValue = charFilter;
			return Self;
		}

		public AnalyzeRequestDescriptor Explain(bool? explain = true)
		{
			ExplainValue = explain;
			return Self;
		}

		public AnalyzeRequestDescriptor Field(Elastic.Clients.Elasticsearch.Field? field)
		{
			FieldValue = field;
			return Self;
		}

		public AnalyzeRequestDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
		{
			FieldValue = field;
			return Self;
		}

		public AnalyzeRequestDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
		{
			FieldValue = field;
			return Self;
		}

		public AnalyzeRequestDescriptor Filter(IEnumerable<Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? filter)
		{
			FilterValue = filter;
			return Self;
		}

		public AnalyzeRequestDescriptor Normalizer(string? normalizer)
		{
			NormalizerValue = normalizer;
			return Self;
		}

		public AnalyzeRequestDescriptor Text(IEnumerable<string>? text)
		{
			TextValue = text;
			return Self;
		}

		public AnalyzeRequestDescriptor Tokenizer(Elastic.Clients.Elasticsearch.Analysis.Tokenizer? tokenizer)
		{
			TokenizerValue = tokenizer;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(AnalyzerValue))
			{
				writer.WritePropertyName("analyzer");
				writer.WriteStringValue(AnalyzerValue);
			}

			if (AttributesValue is not null)
			{
				writer.WritePropertyName("attributes");
				JsonSerializer.Serialize(writer, AttributesValue, options);
			}

			if (CharFilterValue is not null)
			{
				writer.WritePropertyName("char_filter");
				JsonSerializer.Serialize(writer, CharFilterValue, options);
			}

			if (ExplainValue.HasValue)
			{
				writer.WritePropertyName("explain");
				writer.WriteBooleanValue(ExplainValue.Value);
			}

			if (FieldValue is not null)
			{
				writer.WritePropertyName("field");
				JsonSerializer.Serialize(writer, FieldValue, options);
			}

			if (FilterValue is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterValue, options);
			}

			if (!string.IsNullOrEmpty(NormalizerValue))
			{
				writer.WritePropertyName("normalizer");
				writer.WriteStringValue(NormalizerValue);
			}

			if (TextValue is not null)
			{
				writer.WritePropertyName("text");
				SingleOrManySerializationHelper.Serialize<string>(TextValue, writer, options);
			}

			if (TokenizerValue is not null)
			{
				writer.WritePropertyName("tokenizer");
				JsonSerializer.Serialize(writer, TokenizerValue, options);
			}

			writer.WriteEndObject();
		}
	}
}